﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Media;
using System.Data.SQLite;

namespace WinForm图像移动
{
    public partial class Form1 : Form
    {
       // const string filepath = @"..\..\image\";
        const int MARGINPIXELS = (180 - 38);
        const int HEIGHTPIXELS = (240 - 2 * 26);
        int j=0;
       
        public Bitmap carpicutre = new Bitmap("car.bmp");
        public Bitmap linkpicutre = new Bitmap("hoot.bmp");
        
        Rectangle rect = new Rectangle(0, 0, 150, 230);//定义矩形,参数为起点横纵坐标以及其长和宽
        
        SolidBrush b1 = new SolidBrush(Color.Black);//定义单色 黑色 画刷      

        private System.Threading.Timer Graphictimer;

        private static string dbPath = @"nba.db";
        static SQLiteHelper sh;
        //static Timer timer;
        static int k = 0;
        public Form1()
        {
            InitializeComponent();
        }
        private void From_Load(object sender, EventArgs e)
        {
 
            Graphictimer = new System.Threading.Timer((obj) => { GraphicRun(); }, null, 10, 1000);
            // GraphicRun();
        }

        private void GraphicRun()
        {
            
            if (j < 50)
            {
                try
                {
                    
                    Graphics g = Graphics.FromImage(pictureBox2.Image);
                    //Graphics g_circle = Graphics.FromImage(pBox_CircleAera.Image);
                    Pen p = new Pen(Color.Yellow, 1);//设置笔的粗细为,颜色为蓝色
                                                     //Pen p_bule = new Pen(Color.Blue, 1);//设置笔的粗细为,颜色为蓝色
                                                     //Pen p_red = new Pen(Color.Red, 1);//设置笔的粗细为,颜色为红色
                                                     //Pen p_green = new Pen(Color.Green, 1);//设置笔的粗细为,颜色为绿色
                                                     //Pen p_white = new Pen(Color.White, 1);//白色
                    g.FillRectangle(b1, rect);//填充这个矩形 右侧
                                              //g_circle.FillRectangle(b1, rect_circle);//填充这个矩形  左侧画圆

                    #region ck
                    //y_windy = JudegWindy(SensorVolt.windyvolt);
                    //y_weight = k_weight * float.Parse(SensorVolt.weightvolt) + b_weight;

                    //if (y_weight < 0.03)
                    //{
                    //    y_weight = 0;//重量不能为负值，且小于0.03的都认为是跳动的数据
                    //}
                    //y_torque = y_weight * y_margin;
                    //y_margin = k_margin * float.Parse(SensorVolt.marginvolt) + b_margin;
                    //if (y_margin < 0F)//小车幅度值不能超过前臂长度
                    //{
                    //    y_margin = 0;
                    //}

                    //if (y_margin > float.Parse(basicpara.armlength))//小车幅度值不能超过前臂长度
                    //{
                    //    y_margin = float.Parse(basicpara.armlength);
                    //}

                    //y_angle = (float)(0.129653 * float.Parse(SensorVolt.anglevolt) + b_angle);//无锡64圈编码器 塔机回转144齿


                    //display_angle = y_angle;

                    //if (y_angle < 0F)
                    //{
                    //    y_angle += 720;
                    //}
                    //if (y_angle > 360F)
                    //{
                    //    y_angle -= 360;
                    //}
                    //y_height = k_height * float.Parse(SensorVolt.heightvolt) + b_height;
                    //if (y_height > float.Parse(basicpara.armheight))//小车高度值不能超过塔臂高度
                    //{
                    //    y_height = float.Parse(basicpara.armheight);
                    //}



                    //this.Invoke(new EventHandler(delegate
                    //{
                    //    //WriteCurrenParaToTextBox();
                    //    lab_angle.Text = "角度:" + display_angle.ToString("0.0") + "°";
                    //    lab_weight.Text = "重量:" + y_weight.ToString("0.00") + "t";
                    //    lab_height.Text = "高度:" + y_height.ToString("0.0") + "m";
                    //    lab_margin.Text = "变幅:" + y_margin.ToString("0.0") + "m";
                    //    lab_wind.Text = "风速:" + y_windy.ToString("0.0") + "m/s";
                    //    lab_torque.Text = "力矩:" + y_torque.ToString("0.0") + "t*m";
                    //}));
                    #endregion
                    //x_coordinate = (int)((MARGINPIXELS / float.Parse(basicpara.armlength)) * y_margin);
                    //y_coordinate = HEIGHTPIXELS - (int)((HEIGHTPIXELS / float.Parse(basicpara.armheight)) * y_height);
                    int x_coordinate = MARGINPIXELS - 100+j;
                    int y_coordinate = HEIGHTPIXELS - 150+j;
                    g.DrawImage(carpicutre, x_coordinate, y_coordinate + 26);
                    g.DrawImage(linkpicutre, x_coordinate, 0);
                    g.DrawLine(p, x_coordinate + 19, 26, x_coordinate + 19, y_coordinate + 26);//偏移19
                    this.Invoke(new EventHandler(delegate { pictureBox2.Refresh(); }));
                    #region 本机圆圈 ck
                    ////画自己外框圆，圆心坐标是：155,155
                    //float g_x0 = (float.Parse(basicpara.xcoordinate) - sysoriginX - float.Parse(basicpara.armlength)) * other_PixL;
                    //float g_y0 = 310 - (float.Parse(basicpara.ycoordinate) - sysoriginY + float.Parse(basicpara.armlength)) * other_PixL;
                    //float g_x = (float.Parse(basicpara.xcoordinate) - sysoriginX) * other_PixL;
                    //float g_y = 310 - (float.Parse(basicpara.ycoordinate) - sysoriginY) * other_PixL;
                    //origin.X = (int)((float.Parse(basicpara.xcoordinate) - sysoriginX) * other_PixL);
                    //origin.Y = (int)((float.Parse(basicpara.ycoordinate) - sysoriginY) * other_PixL);
                    //g_circle.DrawEllipse(p, (int)g_x0, (int)g_y0, (int)(2 * float.Parse(basicpara.armlength) * other_PixL), (int)(2 * float.Parse(basicpara.armlength) * other_PixL));//大臂圆
                    //g_circle.DrawEllipse(p, (int)(g_x - float.Parse(basicpara.brachionuslength) * other_PixL), (int)(g_y - float.Parse(basicpara.brachionuslength) * other_PixL), (int)(2 * float.Parse(basicpara.brachionuslength) * other_PixL), (int)(2 * float.Parse(basicpara.brachionuslength) * other_PixL));
                    ////画粗圆心 圆心处 
                    //g_circle.DrawEllipse(p_red, (int)g_x - 1, (int)g_y - 1, 2, 2);
                    //g_circle.DrawEllipse(p_red, (int)g_x - 2, (int)g_y - 2, 4, 4);
                    //g_circle.DrawEllipse(p_red, (int)g_x - 3, (int)g_y - 3, 6, 6);
                    //g_circle.DrawEllipse(p_red, (int)g_x - 4, (int)g_y - 4, 8, 8);
                    ////塔吊序号
                    //g_circle.DrawString(basicpara.craneserial, new Font("宋体", 10, FontStyle.Regular), br, (int)g_x, (int)g_y);
                    ////计算塔臂坐标
                    //x_arm = (float)((int)g_x + (float.Parse(basicpara.armlength) * other_PixL) * Math.Cos((2 * PAI / 360) * y_angle));
                    //y_arm = (float)((int)g_y - (float.Parse(basicpara.armlength) * other_PixL) * Math.Sin((2 * PAI / 360) * y_angle));
                    //g_circle.DrawLine(p_red, (int)g_x, (int)g_y, (int)x_arm, (int)y_arm);//画塔臂
                    ////计算尾臂坐标
                    //x_bra = (float)((int)g_x + (float.Parse(basicpara.brachionuslength) * other_PixL) * Math.Cos((2 * PAI / 360) * (y_angle + 180)));
                    //y_bra = (float)((int)g_y - (float.Parse(basicpara.brachionuslength) * other_PixL) * Math.Sin((2 * PAI / 360) * (y_angle + 180)));
                    //g_circle.DrawLine(p_red, (int)g_x, (int)g_y, (int)x_bra, (int)y_bra);//画尾臂
                    ////计算变幅坐标
                    //x_mar = (float)((int)g_x + (y_margin * other_PixL) * Math.Cos((2 * PAI / 360) * y_angle));
                    //y_mar = (float)((int)g_y - (y_margin * other_PixL) * Math.Sin((2 * PAI / 360) * y_angle));
                    //g_circle.DrawEllipse(p_bule, (int)x_mar - 4, (int)y_mar - 4, 8, 8);//在塔臂上标注变幅位置
                    #endregion
                    #region   计算对端塔吊信息 ck
                    //for (int i = 0; i < 5; i++)
                    //{
                    //    if (othercrane[i].flag)
                    //    {
                    //        //对端的坐标点
                    //        g_circle.DrawEllipse(p_red, (int)((othercrane[i].x - sysoriginX) * other_PixL) - 1, (int)(310 - (othercrane[i].y - sysoriginY) * other_PixL) - 1, 2, 2);
                    //        g_circle.DrawEllipse(p_red, (int)((othercrane[i].x - sysoriginX) * other_PixL) - 2, (int)(310 - (othercrane[i].y - sysoriginY) * other_PixL) - 2, 4, 4);
                    //        g_circle.DrawEllipse(p_red, (int)((othercrane[i].x - sysoriginX) * other_PixL) - 3, (int)(310 - (othercrane[i].y - sysoriginY) * other_PixL) - 3, 6, 6);
                    //        g_circle.DrawEllipse(p_red, (int)((othercrane[i].x - sysoriginX) * other_PixL) - 4, (int)(310 - (othercrane[i].y - sysoriginY) * other_PixL) - 4, 8, 8);
                    //        //塔吊序号
                    //        g_circle.DrawString(othercrane[i].seiralnum.ToString(), new Font("宋体", 10, FontStyle.Regular), br, othercrane[i].xcoordinate + 2, othercrane[i].ycoordinate + 2);
                    //        //对端的外框园
                    //        g_circle.DrawEllipse(p_green, (int)((othercrane[i].x - sysoriginX - othercrane[i].armlength) * other_PixL), (int)(310 - (othercrane[i].y - sysoriginY + othercrane[i].armlength) * other_PixL), (int)(2 * othercrane[i].armlength * other_PixL), (int)(2 * othercrane[i].armlength * other_PixL));
                    //        //计算对端的塔臂坐标
                    //        otherx_arm = (float)(othercrane[i].xcoordinate + othercrane[i].armlength * other_PixL * Math.Cos((2 * PAI / 360) * othercrane[i].angle));
                    //        othery_arm = (float)(othercrane[i].ycoordinate - othercrane[i].armlength * other_PixL * Math.Sin((2 * PAI / 360) * othercrane[i].angle));
                    //        g_circle.DrawLine(p_red, othercrane[i].xcoordinate, othercrane[i].ycoordinate, (int)otherx_arm, (int)othery_arm);//画塔臂
                    //        othercrane[i].arm.X = (int)otherx_arm;
                    //        othercrane[i].arm.Y = 310 - (int)othery_arm;
                    //        //计算对端的尾臂坐标
                    //        otherx_arm = (float)(othercrane[i].xcoordinate + othercrane[i].brachionuslength * other_PixL * Math.Cos((2 * PAI / 360) * (othercrane[i].angle + 180)));
                    //        othery_arm = (float)(othercrane[i].ycoordinate - othercrane[i].brachionuslength * other_PixL * Math.Sin((2 * PAI / 360) * (othercrane[i].angle + 180)));
                    //        g_circle.DrawLine(p_red, othercrane[i].xcoordinate, othercrane[i].ycoordinate, (int)otherx_arm, (int)othery_arm);//画尾臂
                    //        othercrane[i].bra.X = (int)otherx_arm;
                    //        othercrane[i].bra.Y = 310 - (int)othery_arm;
                    //        //计算对端的变幅坐标
                    //        otherx_arm = (float)(othercrane[i].xcoordinate + othercrane[i].margin * other_PixL * Math.Cos((2 * PAI / 360) * othercrane[i].angle));
                    //        othery_arm = (float)(othercrane[i].ycoordinate - othercrane[i].margin * other_PixL * Math.Sin((2 * PAI / 360) * othercrane[i].angle));
                    //        g_circle.DrawEllipse(p_bule, (int)otherx_arm - 4, (int)othery_arm - 4, 8, 8);//在塔臂上标注变幅位置
                    //        othercrane[i].mar.X = (int)otherx_arm;
                    //        othercrane[i].mar.Y = 310 - (int)othery_arm;
                    #endregion
                    #region 线到线段的最短距离 ck
                    //if (Math.Abs(float.Parse(basicpara.armheight) - othercrane[i].armheight) < 1)
                    //{
                    //    //double disa=pointToLine((double)x_arm, (double)y_arm, (double)x_bra, (double)y_bra, (double)othercrane[i].arm.X, (double)othercrane[i].arm.Y);
                    //    disa = PointLine_Disp((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra));
                    //    disa = disa / other_PixL;
                    //    disb = PointLine_Disp((double)othercrane[i].bra.X, (double)othercrane[i].bra.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra));
                    //    disb = disb / other_PixL;
                    //    disc = PointLine_Disp((double)x_arm, (double)(310 - y_arm), (double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)othercrane[i].bra.X, (double)othercrane[i].bra.Y);
                    //    disc = disc / other_PixL;
                    //    disd = PointLine_Disp((double)x_bra, (double)(310 - y_bra), (double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)othercrane[i].bra.X, (double)othercrane[i].bra.Y);
                    //    disd = disd / other_PixL;
                    //    IntersectFlag = CheckTwoLineCrose((double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra), (double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)othercrane[i].bra.X, (double)othercrane[i].bra.Y);
                    //    //double sta=0;

                    //    //#region 计算两塔机之间的距离，判断碰撞
                    //   // #region 干涉塔机的前臂与主塔机之间的距离
                    //    if (disa < 8 && (disa <= disb && disa <= disc && disa < disd))
                    //    {
                    //        //sta = Math.Atan2((double)(othercrane[i].arm.Y -  origin.Y), (double)(othercrane[i].arm.X-origin.X));
                    //        //sta = sta * 360 / (2 * PAI);
                    //        if (funReturnRightOrLeft((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra)) > 0)
                    //        {
                    //            if (leftCollisionType != ALARM)
                    //            {
                    //                leftCollisionType = ALARM;
                    //                this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = redpicutre; }));
                    //                rightCollisionType = NORMAL;
                    //                this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = greenpicutre; }));
                    //                if (leftCollisionAlarmFlag == false)
                    //                {
                    //                    if (SuccessfulLandingFlag)
                    //                    {
                    //                        UDP_Event_OtherCraneInterference_Frame((byte)othercrane[i].seiralnum, 0x01);//干涉本塔机塔臂
                    //                        UDP_Event_Type_BreakRule_Frame(0x05, othercrane[i].seiralnum);//相互干涉
                    //                    }
                    //                    PlaySound(soundsfilepath + "左碰撞报警.wav");
                    //                }
                    //                leftCollisionAlarmFlag = true;
                    //            }
                    //        }
                    //        else if (funReturnRightOrLeft((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra)) < 0)
                    //        {
                    //            if (rightCollisionType != ALARM)
                    //            {
                    //                rightCollisionType = ALARM;
                    //                this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = redpicutre; }));
                    //                leftCollisionType = NORMAL;
                    //                this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = greenpicutre; }));

                    //                if (rightCollisionAlarmFlag == false)
                    //                {
                    //                    if (SuccessfulLandingFlag)
                    //                    {
                    //                        UDP_Event_OtherCraneInterference_Frame((byte)othercrane[i].seiralnum, 0x01);//干涉本塔机塔臂
                    //                        UDP_Event_Type_BreakRule_Frame(0x05, othercrane[i].seiralnum);//相互干涉
                    //                    }
                    //                    PlaySound(soundsfilepath + "右碰撞报警.wav");
                    //                }
                    //                rightCollisionAlarmFlag = true;
                    //            }
                    //        }
                    //        else
                    //        {

                    //        }
                    //    }
                    //    else if (disa < 15 && (disa <= disb && disa <= disc && disa < disd))
                    //    {
                    //        if (funReturnRightOrLeft((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra)) > 0)
                    //        {
                    //            if (IntersectFlag == false)
                    //            {
                    //                if (leftCollisionType != WARNING)
                    //                {
                    //                    leftCollisionType = WARNING;
                    //                    this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = yellowpicutre; }));
                    //                    PlaySound(soundsfilepath + "左碰撞预警.wav");
                    //                    rightCollisionType = NORMAL;
                    //                    this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = greenpicutre; }));
                    //                }
                    //            }
                    //        }
                    //        else if (funReturnRightOrLeft((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra)) < 0)
                    //        {
                    //            if (IntersectFlag == false)
                    //            {
                    //                if (rightCollisionType != WARNING)
                    //                {
                    //                    rightCollisionType = WARNING;
                    //                    this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = yellowpicutre; }));
                    //                    PlaySound(soundsfilepath + "右碰撞预警.wav");
                    //                    leftCollisionType = NORMAL;
                    //                    this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = greenpicutre; }));
                    //                }
                    //            }
                    //        }
                    //        else
                    //        {

                    //        }
                    //    }
                    #endregion
                    #region 干涉塔机后臂与主塔机之前的距离 ck
                    //else if (disb < 8 && (disb <= disa && disb <= disc && disb < disd))
                    //{
                    //    //sta = Math.Atan2((double)(othercrane[i].arm.Y -  origin.Y), (double)(othercrane[i].arm.X-origin.X));
                    //    //sta = sta * 360 / (2 * PAI);
                    //    if (funReturnRightOrLeft((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra)) > 0)
                    //    {
                    //        if (leftCollisionType != ALARM)
                    //        {
                    //            leftCollisionType = ALARM;
                    //            this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = redpicutre; }));
                    //            rightCollisionType = NORMAL;
                    //            this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = greenpicutre; }));

                    //            if (leftCollisionAlarmFlag == false)
                    //            {
                    //                if (SuccessfulLandingFlag)
                    //                {
                    //                    UDP_Event_OtherCraneInterference_Frame((byte)othercrane[i].seiralnum, 0x01);//干涉本塔机塔臂
                    //                    UDP_Event_Type_BreakRule_Frame(0x05, othercrane[i].seiralnum);//相互干涉
                    //                }
                    //                PlaySound(soundsfilepath + "左碰撞报警.wav");
                    //            }
                    //            leftCollisionAlarmFlag = true;
                    //        }
                    //    }
                    //    else if (funReturnRightOrLeft((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra)) < 0)
                    //    {
                    //        if (rightCollisionType != ALARM)
                    //        {
                    //            rightCollisionType = ALARM;
                    //            this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = redpicutre; }));
                    //            leftCollisionType = NORMAL;
                    //            this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = greenpicutre; }));

                    //            if (rightCollisionAlarmFlag == false)
                    //            {
                    //                if (SuccessfulLandingFlag)
                    //                {
                    //                    UDP_Event_OtherCraneInterference_Frame((byte)othercrane[i].seiralnum, 0x01);//干涉本塔机塔臂
                    //                    UDP_Event_Type_BreakRule_Frame(0x05, othercrane[i].seiralnum);//相互干涉
                    //                }
                    //                PlaySound(soundsfilepath + "右碰撞报警.wav");
                    //            }
                    //            rightCollisionAlarmFlag = true;
                    //        }
                    //    }
                    //    else
                    //    {

                    //    }
                    //}
                    //else if (disb < 15 && (disb <= disa && disb <= disc && disb < disd))
                    //{
                    //    if (funReturnRightOrLeft((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra)) > 0)
                    //    {
                    //        if (leftCollisionType != WARNING)
                    //        {
                    //            leftCollisionType = WARNING;
                    //            this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = yellowpicutre; }));
                    //            PlaySound(soundsfilepath + "左碰撞预警.wav");
                    //            rightCollisionType = NORMAL;
                    //            this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = greenpicutre; }));
                    //        }
                    //    }
                    //    else if (funReturnRightOrLeft((double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)x_arm, (double)(310 - y_arm), (double)x_bra, (double)(310 - y_bra)) < 0)
                    //    {
                    //        if (IntersectFlag == false)
                    //        {
                    //            if (rightCollisionType != WARNING)
                    //            {
                    //                rightCollisionType = WARNING;
                    //                this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = yellowpicutre; }));
                    //                PlaySound(soundsfilepath + "右碰撞预警.wav");
                    //                leftCollisionType = NORMAL;
                    //                this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = greenpicutre; }));
                    //            }
                    //        }
                    //    }
                    //    else
                    //    {

                    //    }
                    //}
                    #endregion
                    #region 主塔机前臂与干涉塔机之前的距离 ck
                    //else if (disc < 8 && (disc <= disa && disc <= disb && disc < disd))
                    //{
                    //    //sta = Math.Atan2((double)(othercrane[i].arm.Y -  origin.Y), (double)(othercrane[i].arm.X-origin.X));
                    //    //sta = sta * 360 / (2 * PAI);
                    //    //主塔机的前臂点到干涉塔机臂，左右计算出来左右和实际报警左右值相反
                    //    if (funReturnRightOrLeft((double)x_arm, (double)(310 - y_arm), (double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)othercrane[i].bra.X, (double)othercrane[i].bra.Y) > 0)
                    //    {
                    //        if (IntersectFlag == false)
                    //        {
                    //            if (rightCollisionType != ALARM)
                    //            {
                    //                rightCollisionType = ALARM;
                    //                this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = redpicutre; }));
                    //                leftCollisionType = NORMAL;
                    //                this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = greenpicutre; }));

                    //                if (rightCollisionAlarmFlag == false)
                    //                {
                    //                    if (SuccessfulLandingFlag)
                    //                    {
                    //                        UDP_Event_OtherCraneInterference_Frame((byte)othercrane[i].seiralnum, 0x01);//干涉本塔机塔臂
                    //                        UDP_Event_Type_BreakRule_Frame(0x05, othercrane[i].seiralnum);//相互干涉
                    //                    }
                    //                    PlaySound(soundsfilepath + "右碰撞报警.wav");
                    //                }
                    //                rightCollisionAlarmFlag = true;
                    //            }
                    //        }
                    //    }
                    //    else if (funReturnRightOrLeft((double)x_arm, (double)(310 - y_arm), (double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)othercrane[i].bra.X, (double)othercrane[i].bra.Y) < 0)
                    //    {
                    //        if (leftCollisionType != ALARM)
                    //        {
                    //            leftCollisionType = ALARM;
                    //            this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = redpicutre; }));
                    //            rightCollisionType = NORMAL;
                    //            this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = greenpicutre; }));

                    //            if (leftCollisionAlarmFlag == false)
                    //            {
                    //                if (SuccessfulLandingFlag)
                    //                {
                    //                    UDP_Event_OtherCraneInterference_Frame((byte)othercrane[i].seiralnum, 0x01);//干涉本塔机塔臂
                    //                    UDP_Event_Type_BreakRule_Frame(0x05, othercrane[i].seiralnum);//相互干涉
                    //                }
                    //                PlaySound(soundsfilepath + "左碰撞报警.wav");
                    //            }
                    //            leftCollisionAlarmFlag = true;
                    //        }
                    //    }
                    //    else
                    //    {

                    //    }
                    //}
                    //else if (disc < 15 && (disc <= disa && disc <= disb && disc < disd))
                    //{
                    //    if (funReturnRightOrLeft((double)x_arm, (double)(310 - y_arm), (double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)othercrane[i].bra.X, (double)othercrane[i].bra.Y) > 0)
                    //    {
                    //        if (rightCollisionType != WARNING)
                    //        {
                    //            rightCollisionType = WARNING;
                    //            this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = yellowpicutre; }));
                    //            PlaySound(soundsfilepath + "右碰撞预警.wav");
                    //            leftCollisionType = NORMAL;
                    //            this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = greenpicutre; }));
                    //        }
                    //    }
                    //    else if (funReturnRightOrLeft((double)x_arm, (double)(310 - y_arm), (double)othercrane[i].arm.X, (double)othercrane[i].arm.Y, (double)othercrane[i].bra.X, (double)othercrane[i].bra.Y) < 0)
                    //    {
                    //        if (leftCollisionType != WARNING)
                    //        {
                    //            leftCollisionType = WARNING;
                    //            this.Invoke(new EventHandler(delegate { pic_LeftCollison.Image = yellowpicutre; }));
                    //            PlaySound(soundsfilepath + "左碰撞预警.wav");
                    //            rightCollisionType = NORMAL;
                    //            this.Invoke(new EventHandler(delegate { pic_RightCollison.Image = greenpicutre; }));
                    //        }
                    //    }
                    //    else
                    //    {

                    //    }
                    //}
                    #endregion
                    #region ck               
                    //更新图片

                    //this.Invoke(new EventHandler(delegate
                    //{
                    //    pBox_CircleAera.Refresh();
                    //}));            

                    //p.Dispose();
                    // g_circle.Dispose();//释放内存
                    //p_bule.Dispose();
                    //p_red.Dispose();
                    //p_green.Dispose();
                    //p_white.Dispose();
                    #endregion
                    g.Dispose();//释放内存
                    j +=5;
                    //  Monitor.Exit(this);//取消锁定
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        

        private void button3_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
           form2. ShowDialog();
            //Application.Run(new Form2());
        }

        private void button4_Click(object sender, EventArgs e)
        {

            SoundPlayer sp = new SoundPlayer();
            sp.SoundLocation = @"02.wav";
            sp.Load();
            sp.Play();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string tableName = "Stars";
            sh = new SQLiteHelper(dbPath);

            k++;
            string sql = "insert into Stars (Name, Team,Number) values (@Name, @Team, @Number)";

            SQLiteParameter[] parameter = new SQLiteParameter[]
            {
                new SQLiteParameter("@Name","tom"+k.ToString()),
                new SQLiteParameter("@Team","laker"),
                new SQLiteParameter("@Number",21+k)
            };
           int n= sh.ExecuteNonQuery(sql, parameter);
            MessageBox.Show(n.ToString());
        }
    }
}
